const {ccclass, property} = cc._decorator;

@ccclass
export default class Card extends cc.Component {

    private _card:QM.Card;
    private _isSelect:boolean=false;
    private _point:QM.QPoint;

    sprite:cc.Sprite;


    set isSelect(value){
        this._isSelect = value;        
        this.select();        
    }
    get isSelect(){
        return this._isSelect;
    }

    set point(value:QM.QPoint){
        this._point = value;
        if(this.point==QM.QPoint.Bottom){
            this.node.on(cc.Node.EventType.TOUCH_START,()=>{
                this.isSelect = !this._isSelect;
            })
        }        
    }
    get point(){
        return this._point;
    }
    
    set card(value:QM.Card){               
        this._card = value; 
        this.show();
    }

    get card():QM.Card{
        return this._card;
    }

    get value(){
        return QM.CName.indexOf(this.card.name);
    }
    get cvalue(){
        return QM.CColor.indexOf(this.card.color);
    }

    

    onLoad () {
        this.sprite = this.node.getComponent(cc.Sprite);
    }

    show(){        
        if(!this.sprite){
            this.sprite = this.node.getComponent(cc.Sprite);
        }
        var path="Texture/Pokers/"+this.card.title;    
        var texture = cc.loader.getRes(path,cc.SpriteFrame)                      
        this.sprite.spriteFrame = texture;                        
    }

    select(){
        var dir = this.isSelect?1:-1;        
        var a = cc.moveBy(0.1,0,dir*20);
        this.node.runAction(a)
    }

}
